package com.example.demo.common;

import com.example.demo.model.User;
import org.apache.tomcat.util.bcel.classfile.Constant;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ling
 * Date: 2023-01-19
 * Time: 21:25
 */
@Component
public class SessionUtil {
    /**
     * 查询当前登录用户的session信息
     * @param request
     * @return
     */
    public static final String SESSION_USERINFO_KEY = "BANK_SESSION_USER_KEY";

    public static User getLoginUser(HttpServletRequest request) {
        HttpSession session = request.getSession(false);
        if(session!=null && session.getAttribute(SESSION_USERINFO_KEY)!=null) {
            User userInfo = (User) session.getAttribute(SESSION_USERINFO_KEY);
            return userInfo;
        }
        return null;
    }
}
